package com.school.graduation.mine.model;

import android.content.Context;

import com.school.graduation.bean.MineReleasedCallBack;
import com.school.graduation.internet.API;
import com.school.graduation.internet.GetMineReleasedInterface;
import com.school.graduation.mine.presenter.MineReleasedPresenter;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class MineReleasedModel implements MineReleasedModelInterface{

    private Context mContext;
    private MineReleasedPresenter mPresenter;

    public MineReleasedModel(Context context, MineReleasedPresenter presenter) {
        mContext = context;
        mPresenter = presenter;
    }

    @Override
    public void loadMineReleasedGoods(String userId) {
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(API.baseUrl)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        GetMineReleasedInterface getMineReleasedInterface = retrofit.create(GetMineReleasedInterface.class);
        Call<MineReleasedCallBack> mineReleasedCallBackCall = getMineReleasedInterface.getMineReleased(userId);
        mineReleasedCallBackCall.enqueue(new Callback<MineReleasedCallBack>() {
            @Override
            public void onResponse(Call<MineReleasedCallBack> call, Response<MineReleasedCallBack> response) {
                if (response.isSuccessful()){
                    mPresenter.loadMineReleasedGoodsSuccess(response.body());
                }
            }

            @Override
            public void onFailure(Call<MineReleasedCallBack> call, Throwable t) {

            }
        });
    }
}
